#ifndef CORE_IMAGE_H
#define CORE_IMAGE_H

#include "Drawing/Color.h"
#include "GameCore/ImagePixelFormat.h"

namespace core {

	class Image
	{
	public:
		Image( unsigned int width, unsigned int height, ImagePixelFormat pixelFormat );
		~Image();

		inline unsigned int GetWidth() const { return m_width; }
		inline unsigned int GetHeight() const { return m_height; }
		inline unsigned char* GetRawData() const { return m_rawData; }

		inline ImagePixelFormat GetPixelFormat() const { return m_pixelFormat; }

		inline bool HasAlpha() const {
			switch( m_pixelFormat ) {
				case ImagePixelFormat::Rgba: return true;
				case ImagePixelFormat::Rgb: return false;
				default: return true;
			};
		}

		inline unsigned int GetBytesPerPoint() const {
			switch( m_pixelFormat ) {
				case ImagePixelFormat::Rgba: return 4;
				case ImagePixelFormat::Rgb: return 3;
				default: return 4;
			};
		}

		unsigned char& operator[]( unsigned int index );
		const unsigned char& operator[]( unsigned int index ) const;

		drawing::Color GetColor( unsigned int x, unsigned int y ) const;
		void SetColor( const drawing::Color& color, unsigned int x, unsigned int y );

	private:
		unsigned int GetIndex( unsigned int x, unsigned int y ) const;

	private:
		unsigned char* m_rawData;
		unsigned int m_width;
		unsigned int m_height;
		ImagePixelFormat m_pixelFormat;
	};
}
#endif
